#ifndef SHADING_H
#define SHADING_H
#include <vector>
#include <QRgb>

#include "defs.h"
#include "model/vertex.h"
#include "model/scene.h"
#include "method/wireframe.h"
#include "model/lighting.h"

class ConstantShading: public ZBuffer {
protected:
    QRgb glow(const Scene *s, const Lighting &properties, const Point &point, const Point &normalVector);

public:
    virtual void draw(QWidget *container, Scene *projection);
};

class GouraudShading: public ConstantShading {
    struct GouroudEdge {
        light_t r, g, b;
        light_t ir, ig, ib;
        coord x, z;
        coord ix, iz;
        coord max;

        GouroudEdge(const Vertex &begin, const Vertex &end, const QRgb &colorBegin, const QRgb &colorEnd) {
            coord height = (end.y - begin.y);

            this->x = begin.x;
            this->z = begin.z;
            this->ix = (end.x - begin.x)/height;
            this->iz = (end.z - begin.z)/height;
            this->max = end.y;

            this->r = qRed(colorBegin);
            this->g = qGreen(colorBegin);
            this->b = qBlue(colorBegin);

            this->ir = (qRed(colorEnd)-r)/height;
            this->ig = (qGreen(colorEnd)-g)/height;
            this->ib = (qBlue(colorEnd)-b)/height;

        }

        bool operator < (const GouroudEdge& other) const {
            return this->x < other.x;
        }

        GouroudEdge& operator++ () {
            x += ix;
            z += iz;
            r += ir;
            g += ig;
            b += ib;
            return *this;
        }
    };
    virtual void draw(QWidget *container, Scene *projection);

};

#endif // SHADING_H

